<?php

namespace App\Models\Orm;
use App\Models\User;
use Illuminate\Database\Eloquent\Model;

class CoinLog extends Model
{
    const TABLE_NAME = 'coin_store_log';
    const PRIMARY_KEY = 'id';

    protected $table = self::TABLE_NAME;
    //主键id
    protected $primaryKey = self::PRIMARY_KEY;
    //查询字段
    protected $visible = [];
    //加黑名单
    protected $guarded = [];
    // 上线状态
    const STATUS_OFF = 0;           // 下线
    const STATUS_ON = 1;            // 上线

    const IGNORE = 0;//申请存币
    const APPLY = 1;//申请存币
    const PASS = 2;//通过收到币
    const FAIL = 3;//拒绝没有收到币
    const  MAN = 4;//人工充币
    const  DRAW = 5;//人工充币


    const Wallet = 1;//申请存币
    const Monye = 2;//通过收到币

    const WU = 0;//申请存币
    const WEIXIN = 1;//申请存币
    const ZHIFUBAO = 2;//通过收到币
    const BANK = 3;//通过收到币


    // 状态描述
    public static $status_text = [
        self::IGNORE => '存币订单待确认',
        self::APPLY => '存币订单处理中',
        self::PASS => '存币订单成功',
        self::FAIL => '存币订单失败',
        self::MAN => '后台客服存币处理',
        self::DRAW => '后台客服提币处理',

    ];


    // 状态描述
    public static $status_pay = [
        self::WU => '无',
        self::WEIXIN => '微信支付',
        self::ZHIFUBAO => '支付宝支付',
        self::BANK => '银行卡支付',

    ];




    // 充值类型
    public static $status_type = [
        self::Wallet => '钱包充币',
        self::Monye => '现金充币',


    ];


    /**
     * 获取当前记录动作描述
     * @param $action
     * @return string
     */
    public static function getActionText($status)
    {
        return self::$status_text[$status] ?: '';
    }


    public static function getActionType($status)
    {
        return self::$status_type[$status] ?: '';
    }


    public static function getActionPay($status)
    {
        return self::$status_pay[$status] ?: '';
    }


    /**
     * 查询提现记录对应的用户信息
     *
     * @return mixed
     */
    public function getUser()
    {
        return $this->hasOne(\App\Models\Orm\User::class, 'id', 'user_id')->getResults();
    }

    /**
     * 查询提现记录对应后台操作人信息
     *
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     */
    public function getAdmin()
    {
        return $this->hasOne(User::class, 'id', 'admin_id')->getResults();
    }

    /**
     * 获取某用户所有未被处理的提现记录
     *
     * @param $user_id
     * @param string $order_by_column
     * @param string $order_by
     * @return mixed
     */
//    public static function getUserInitRecord($user_id, $order_by_column = 'id', $order_by = 'desc')
//    {
//        return self::where('user_id', $user_id)
//            ->where('status', self::STATUS_INIT)
//            ->orderBy($order_by_column, $order_by)
//            ->get();
//    }

}